<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>客户绑定</title>
    <meta name="viewport" content="width=device-width"/>
    <script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
    <script src="js/ajax.js"></script>
</head>
<body>
<div id="app" style="display:none;">
    <h2 style="color:#666;text-align:center;">客户绑定</h2>

    <div class="weui-cells weui-cells_form">
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">单位名称</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" v-model="bxm.cName"
                       placeholder="请输入单位名称"/>
            </div>
            <div class="weui-cell__ft">
                <i class="weui-icon-warn"></i>
            </div>
        </div>

        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">联系人姓名</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" v-model="bxm.name"
                       placeholder="请输入联系人姓名"/>
            </div>
            <div class="weui-cell__ft">
                <i class="weui-icon-warn"></i>
            </div>
        </div>


        <div class="weui-cell">
            <div class="weui-cell__bd">
                <div class="weui-uploader">
                    <div class="weui-uploader__hd">
                        <p class="weui-uploader__title">营业执照</p>
                        <!--<div class="weui-uploader__info">0/5</div>-->
                    </div>
                    <div class="weui-uploader__bd">
                        <ul class="weui-uploader__files">
                            <li id="zhizhao"
                                class="weui-uploader__file"
                                style="display:none;"
                            >

                            </li>

                        </ul>

                        <div class="weui-uploader__input-box" onclick="upload()">

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <a href="javascript:;" onclick="bangding()" style="width:90%;margin-top:20px;" class="weui-btn weui-btn_primary">绑定</a>
</div>

<!-- body 最后 -->
<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>

<!-- 如果使用了某些拓展插件还需要额外的JS -->
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/swiper.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/city-picker.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script src="js/jssdk.js"></script>
<script src="js/getopenid.js"></script>
<script>


    getopenid(function(openid){
        v.bxm.openid = openid;

        $.showLoading("正在加载...");
        $.get("/find_baoxiuman_byopenid", {openid: openid}, function (data) {
            if (data) {
                localStorage.baoxianMan = JSON.stringify(data);
                location = 'baoxiuman_main.html';
            }else{
                app.style.display= "";
                $.hideLoading();
            }
        });
    });

    var v = new Vue({
        el: "#app",
        data: {
            bxm:{
                name:"",
                cName:"",
                zhizhao:"",
                openid:''
            }
        }
    });

    jssdk(function(){}, ['chooseImage','getLocalImgData','uploadImage']);

    function upload(){
        wx.chooseImage({
            count: 1, // 默认9
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                var localIds = res.localIds; // 返回选定照片的本地ID列表，
                $.showLoading("请稍后...")
                wx.getLocalImgData({
                    localId: localIds[0], // 图片的localID
                    success: function (res) {
                        var localData = res.localData;
                        $.post("/ossupload",{
                            base64:localData
                        },function(data){
                            //data ==>pName

                            v.bxm.zhizhao = data;
                            $.hideLoading();

                            v.bxm.zhizhao = "http://java59.hfbdqn.cn/ossdownload?pName=" +data;
                            zhizhao.style.display = "";
                            zhizhao.style.background = "url(http://java59.hfbdqn.cn/ossdownload?pName="
                                +data+") no-repeat";
                            zhizhao.style['background-size'] = "contain";
                        })
                    }
                });
            }
        });

    }

    function bangding() {
        $.ajax({
            type: 'post',
            url: 'baoxian_man_bind',
            data: JSON.stringify(v.bxm),
            contentType: 'application/json;charset=utf-8',
            success: function (data) {
                if (data) {
                    $.toast("谢谢您的绑定！")
                    localStorage.baoxianMan = JSON.stringify(data);
                    location = 'baoxiuman_main.html'//会员中心

                } else {
                    $.toast("绑定失败，请您重试！", "cancel")
                }

            }
        });
    }
</script>

</body>
</html>